package controller

import (
	"context"
	pb "gitee.com/micro-services/protocol/user/server"
	log "github.com/sirupsen/logrus"
	"micro.user.server/lib"

	"micro.user.server/ao"
	"micro.user.server/plugins"
)

type UserController struct{}

func (uc *UserController) CreateUser(ctx context.Context, r *pb.CreateUserReq, w *pb.CreateUserRsp) error {
	log.Infof("call request:%+v", r)

	err := ao.CreatHotelUser(r)
	if err != nil {
		log.Errorf("create hotel user error:%+v", err)
		return err
	}

	w.Msg = lib.Msg(lib.Success)
	w.RetCode = lib.Success

	return nil
}

func (uc *UserController) QueryUserInfo(ctx context.Context, r *pb.QueryUserInfoReq, w *pb.QueryUserInfoRsp) error {
	log.Infof("call request:%+v", r)

	list, err := ao.UsrList(r)
	if err != nil {
		log.Errorf("query user list error:%+v", err)
		return err
	}

	w.Info = list

	plugins.DealWithTracer(ctx, "go.micro.user.server.QueryUserInfo", r, w)

	return nil
}

func (uc *UserController) UpdateUserInfo(ctx context.Context, r *pb.UpdateUserInfoReq, w *pb.UpdateUserInfoRsp) error {
	log.Infof("call request:%+v", r)

	if err := ao.UpdateUser(r); err != nil {
		log.Errorf("update user error:%+v", err)
		return err
	}

	w.Msg = lib.Msg(lib.Success)
	w.RetCode = lib.Success

	plugins.DealWithTracer(ctx, "go.micro.user.server.UpdateUserInfo", r, w)
	return nil
}

func (uc *UserController) DeleteUser(ctx context.Context, r *pb.DeleteUserReq, w *pb.DeleteUserRsp) error {
	log.Infof("call request:%+v", r)

	if err := ao.DeleteUser(r); err != nil {
		log.Errorf("update user error:%+v", err)
		return err
	}

	w.Msg = lib.Msg(lib.Success)
	w.RetCode = lib.Success

	plugins.DealWithTracer(ctx, "go.micro.user.server.DeleteUser", r, w)
	return nil
}

func (uc *UserController) UserList(ctx context.Context, r *pb.UserListReq, w *pb.UserListRsp) error {

	return nil
}
